Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add nudge braze email using commands #388

Merged
merged 6 commits into from
Jan 31, 2024
Merged

feat: add nudge braze email using commands #388

merged 6 commits into from
Jan 31, 2024

Conversation

brobro10000
Copy link
Member

@brobro10000 brobro10000 commented Jan 18, 2024

Creates a command to send nudge emails to accepted assignments that are 14 and 30 days in advance for only executive education courses.

@brobro10000 brobro10000 force-pushed the hu/ent-8166 branch 9 times, most recently from 9fa20d4 to fc242fb Compare January 22, 2024 19:34
@@ -104,7 +104,7 @@ class AssignmentAutomaticExpiredReason:
"""
Reason for assignment automatic expiry.
"""
NIENTY_DAYS_PASSED = 'NIENTY_DAYS_PASSED'
NINETY_DAYS_PASSED = 'NINETY_DAYS_PASSED'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed a typo in this constant, refactored all cases where its used with the correct spelling for the value and variable

@brobro10000 brobro10000 force-pushed the hu/ent-8166 branch 2 times, most recently from e8ece62 to af3d2ed Compare January 22, 2024 19:51
@brobro10000 brobro10000 marked this pull request as ready for review January 22, 2024 19:55
@brobro10000 brobro10000 force-pushed the hu/ent-8166 branch 5 times, most recently from 5cba6e6 to c62d751 Compare January 23, 2024 17:16
@iloveagent57
Copy link
Contributor

iloveagent57 commented Jan 23, 2024

You want to filter for only allocated assignments. accepted means they've already redeemed/enrolled.

This is the main thing to fix (plus tests) and the reason for requesting changes.

@iloveagent57
Copy link
Contributor

Ah, I misunderstood the intent here. The fact that we're sending reminders made me think you wanted allocated assignments. But you actually do want accepted ones. Let's take this conv off github for now, I think there's some nuance here.

@brobro10000 brobro10000 force-pushed the hu/ent-8166 branch 5 times, most recently from 55c6222 to 456b4e5 Compare January 25, 2024 16:02
@brobro10000 brobro10000 force-pushed the hu/ent-8166 branch 8 times, most recently from c11dcf9 to 4c9dba8 Compare January 29, 2024 18:58
Copy link
Contributor

@iloveagent57 iloveagent57 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking really good!

Comment on lines 176 to 204
class LearnerContentAssignmentNudgeRequestSerializer(serializers.Serializer):
"""
Request serializer to validate nudge endpoint query params.

For view: LearnerContentAssignmentAdminViewSet.nudge
"""
assignment_uuids = serializers.ListField(
child=serializers.UUIDField(),
allow_empty=False
)
days_before_course_start_date = serializers.IntegerField(
min_value=1
)


class LearnerContentAssignmentNudgeResponseSerializer(serializers.Serializer):
"""
Response serializer for nudge endpoint.

For view: LearnerContentAssignmentAdminViewSet.nudge
"""
nudged_assignment_uuids = serializers.ListField(
child=serializers.UUIDField(),
)
unnudged_assignment_uuids = serializers.ListField(
child=serializers.UUIDField(),
)


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice

enterprise_access/apps/content_assignments/api.py Outdated Show resolved Hide resolved
enterprise_access/apps/content_assignments/api.py Outdated Show resolved Hide resolved
enterprise_access/apps/content_assignments/api.py Outdated Show resolved Hide resolved
enterprise_access/apps/content_assignments/api.py Outdated Show resolved Hide resolved
enterprise_access/apps/content_assignments/api.py Outdated Show resolved Hide resolved
@brobro10000 brobro10000 force-pushed the hu/ent-8166 branch 3 times, most recently from 11a2d75 to 5e9d818 Compare January 30, 2024 08:34
Copy link
Contributor

@iloveagent57 iloveagent57 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, but please address that **kwargs thing before merging. 👍

Comment on lines 353 to 394
@extend_schema(
tags=[CONTENT_ASSIGNMENT_ADMIN_CRUD_API_TAG],
summary='Nudge assignments by UUID.',
request=LearnerContentAssignmentNudgeRequestSerializer,
parameters=None,
responses={
status.HTTP_200_OK: LearnerContentAssignmentNudgeResponseSerializer,
status.HTTP_422_UNPROCESSABLE_ENTITY: None,
}
)
@permission_required(CONTENT_ASSIGNMENT_ADMIN_WRITE_PERMISSION, fn=assignment_admin_permission_fn)
@action(detail=False, methods=['post'])
def nudge(self, request, *args, **kwargs):
"""
Send nudges to a list of learners with associated ``LearnerContentAssignment``
record by list of uuids.

```
Raises:
400 If assignment_uuids list length is 0 or the value for days_before_course_start_date is less than 1
422 If the nudge_assignments call fails for any other reason
```
"""
serializer = LearnerContentAssignmentNudgeRequestSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
assignment_configuration_uuid = self.requested_assignment_configuration_uuid
assignments = self.get_queryset().filter(
assignment_configuration__uuid=assignment_configuration_uuid,
uuid__in=serializer.data['assignment_uuids'],
)
days_before_course_start_date = serializer.data['days_before_course_start_date']
try:
result = assignments_api.nudge_assignments(
assignments,
assignment_configuration_uuid,
days_before_course_start_date
)
response_serializer = LearnerContentAssignmentNudgeResponseSerializer(data=result)
response_serializer.is_valid(raise_exception=True)
return Response(data=response_serializer.data, status=status.HTTP_200_OK)
except Exception: # pylint: disable=broad-except
return Response(status=status.HTTP_422_UNPROCESSABLE_ENTITY)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really, really well-factored and well-documented view, with really clear validation and abstractions around our business logic. Nice work, hang this on your fridge!

@brobro10000 brobro10000 force-pushed the hu/ent-8166 branch 7 times, most recently from 8949677 to 8ccb407 Compare January 31, 2024 15:31
Copy link
Contributor

@macdiesel macdiesel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@brobro10000 brobro10000 merged commit c1a4ad6 into main Jan 31, 2024
4 checks passed
@brobro10000 brobro10000 deleted the hu/ent-8166 branch January 31, 2024 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants